//! \file CKey.cpp
// -----------------------------------------------------------------------------
//! This program is free software; you can redistribute it and/or
//! modify it under the terms of the GNU General Public License
//! as published by the Free Software Foundation; either version 2
//! of the License, or (at your option) any later version.
//!
//! This program is distributed in the hope that it will be useful,
//! but WITHOUT ANY WARRANTY; without even the implied warranty of
//! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//! GNU General Public License for more details.
//!
//! You should have received a copy of the GNU General Public License
//! along with this program; if not, write to the Free Software Foundation,
//! Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// -----------------------------------------------------------------------------

#include "CKey.h"

namespace code_sheriff
{

// TODO: comment <here>


//! \brief TODO: document
//!
//! TODO: document
//! TODO: the plugins need to provide the key lists and be able to register
//! them with the host.  How we going to go about that?
static const struct CKey::TEntry EntryTable[KEY_END_OF_LIST] =
{
  // KEY_CONFIG_FILE
  {
    "",
    "config",
    "",
    "The file being used for configuration settings."
  },

  // KEY_WHITE_SPACE_TAB_POLICY
  {
    "",
    "config",
    "WHITE_SPACE_TAB_POLICY",
    "The file being used for configuration settings.",
  },

  // KEY_WHITE_SPACE_TAB_SIZE
  {
    "",
    "config",
    "WHITE_SPACE_TAB_SIZE",
    "The file being used for configuration settings.",
  },

  // KEY_WHITE_SPACE_INDENT_SIZE
  {
    "",
    "config",
    "WHITE_SPACE_INDENT_SIZE",
    "The file being used for configuration settings.",
  },

  // KEY_WHITE_SPACE_PRINT_MARGIN
  {
    "",
    "config",
    "WHITE_SPACE_PRINT_MARGIN",
    "The file being used for configuration settings.",
  },

  // KEY_INVALID
  {
    "",
    "INVALID",
    "",
    "This setting is invalid.",
  }

};


// TODO: remove

//const CKey::TKEY CKey::KEY_INVALID = 0;


//  CKey::CKey()
//  {
//    // TODO Auto-generated constructor stub
//
//  }
//
//  CKey::~CKey()
//  {
//    // TODO Auto-generated destructor stub
//  }


// =============================================================================
// CKey::get
// -----------------------------------------------------------------------------
const struct CKey::TEntry* CKey::get(TKEY Key)
{
  // Validate our arguments.
  if (Key >= KEY_END_OF_LIST)
    return (&(EntryTable[KEY_INVALID]));

  // Return a pointer to the requested key table entry.
  return (&(EntryTable[Key]));
}


// =============================================================================
// CKey::toKey
// -----------------------------------------------------------------------------
TKEY CKey::toKey(std::string Value)
{
  TKEY Key; // TODO: document index for iterating the conversion table.

  // Search for the option in our conversion table.
  for (Key = 0; Key < KEY_END_OF_LIST; Key++)
  {
    // Compare against the short name.
    if (EntryTable[Key].Short == Value)
      { return (Key); } // Return the located key.

    // Compare against the long name.
    if (EntryTable[Key].Long == Value)
      { return (Key); } // Return the located key.
  }

  // Otherwise the key could not be found.
  return (KEY_INVALID);
}


} // namespace code_sheriff

